from django.http import JsonResponse
from .models import User
from .serializers import UserSerializer
from django.shortcuts import render


def index(request):
    users = User.objects.all()
    serializer = UserSerializer(users, many=True)
    return JsonResponse({'users': serializer.data}, safe=True)






    #这种情况能在前段接受到数据并展示
    # users = [
    #     {'name': '张三', 'age': 30, 'sex': '男'},
    #     {'name': '李四', 'age': 40, 'sex': '女'},
    # ]
    # return JsonResponse({'users': users})


def show(request):
    users = models.User.objects.all()
    return render(request, 'vue_django_job/show.html', {'users': users})
